<template>
	<view>


		<view class="">
			<template>
				<view class="flex a-c  p2" style="width: 600px;">
					<view class="">
						名称
					</view>
					<uni-easyinput class="ml2" v-model="name" placeholder="名称">
					</uni-easyinput>
					<view class="  p2" style="margin-left: 45px;">
						<button class=" " @click="on_add()" type="primary" style="width: 80px;" size="mini">保存</button>
					</view>
				</view>
				<view class="p2" style="width: 95%;">
					<mEditor :value='content' @huidiao="huidiao" ids="content"></mEditor>
				</view>
			</template>

			<view class=" " v-for="(vo,index) in list">
				<view class="p2 cff" style="width: 95%; color: #000; ">


					<!-- <pre @click="on_copy(vo.val)"   class="p2 cff" style="color: #FF4500;background-color: #000;">
			      <code    class="clip">{{vo.val}} </code>
				 </pre> -->
					<view @click="copy(vo.val_html)" class="p1 cff" style="color: #FF4500;background-color: #000;">
						<view class="  flex  ">
							<text class="f28   w800" style="color: #FF4500;">{{vo.name}}</text>
						</view>
						<rich-text class="l5 f28" :nodes="vo.val"></rich-text>
					</view>




				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import h5Copy from '@/static/junyi-h5-copy.js'
	export default {
		components: {

		},
		props: {
			list_goods: {
				type: Array,
				default: function() {
					return [] //数据
				}
			}
		},
		watch: {
			content(val) {

			},
		},

		data() {
			return {
				codetime: 8,
				info: {},
				list: [],
				content: '',
				name: ''
			};
		},
		mounted() {
			this.init();

		},
		methods: {

			copy(url) {
				let content = url // 复制内容，必须字符串，数字需要转换为字符串
				const result = h5Copy(content)
				if (result === false) {
					uni.showToast({
						title: '不支持',
					})
				} else {
					uni.showToast({
						title: '复制成功',
						icon: 'none'
					})
				}

			},

			huidiao(val) {
				this.content = val;

			},
			delHtmlTag(str) {
				return str.replace(/<[^>]+>/g, "");
			},


			on_copy(url) {

				uni.setClipboardData({
					data: url,
					success: function() {
						uni.showToast({
							title: '复制成功'
						})

					}
				});
			},
			on_add() {
				if (!this.name) {
					uni.showToast({
						title: '请输入名称'
					})
					return
				}
				if (!this.content) {
					uni.showToast({
						title: '请输入内容'
					})
					return
				}

				this.Htpp.set_code_add(this.content, this.name).then(ret => {




				})



			},
			on_copy(url) {
				var url = this.delHtmlTag(url);
				uni.setClipboardData({
					data: url,
					success: function() {
						uni.showToast({
							title: '复制成功'
						})


					}
				});


			},

			init() {

				this.Htpp.set_code_init('').then(ret => {

					this.list = ret.data.list
					for (var i = 0; i < this.list.length; i++) {
						var val = this.list[i]['val'];
						val = val.replace(/<p>/g, "")
						val = val.replace(/<\/p>/g, "\r\n")
						val = val.replace(/<br>/g, "")
						val = val.replace(/&lt;/g, "<")
						val = val.replace(/&gt;/g, ">")
						val = val.replace(/&emsp;/g, "\t")
						val = val.replace(/&nbsp;/g, "\t")


						this.list[i]['val_html'] = val;
					}



				})



			},







		}
	}
</script>

<style lang="scss">
	@import "@/static/obsidian.min.css";
</style>